home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / unixcpio.gz / unixnet.cpio / iface.c < prev    next >
C/C++ Source or Header  |  1994-07-11  |  1KB  |  58 lines

  1. #include "global.h"
  2. #include "iface.h"
  3.  
  4. struct interface *
  5. if_lookup(name)
  6. char *name;
  7. {
  8.     register struct interface *iface;
  9.  
  10.     for(iface = ifaces; iface != NULLIF; iface = iface->next)
  11.         if(strcmp(iface->name,name) == 0)
  12.             break;
  13.     return iface;
  14. }
  15. /* Divert output packets from one interface to another. Useful for ARP
  16.  * and digipeat frames coming in from receive-only interfaces
  17.  */
  18. doforward(argc,argv)
  19. int argc;
  20. char *argv[];
  21. {
  22.     struct interface *iface,*iface1;
  23.     
  24.  
  25.     if(argc < 2){
  26.         for(iface = ifaces; iface != NULLIF; iface = iface->next){
  27.             if(iface->forw != NULLIF){
  28.                 printf("%s -> %s\n",iface->name,iface->forw->name);
  29.             }
  30.         }
  31.         return 0;
  32.     }
  33.     if((iface = if_lookup(argv[1])) == NULLIF){
  34.         printf("Interface %s unknown\n",argv[1]);
  35.         return 1;
  36.     }
  37.     if(argc < 3){
  38.         if(iface->forw == NULLIF)
  39.             printf("%s not forwarded\n",iface->name);
  40.         else
  41.             printf("%s -> %s\n",iface->name,iface->forw->name);
  42.         return 0;
  43.     }
  44.     if((iface1 = if_lookup(argv[2])) == NULLIF){
  45.         printf("Interface %s unknown\n",argv[2]);
  46.         return 1;
  47.     }
  48.     if(iface1 == iface){
  49.         /* Forward to self means "turn forwarding off" */
  50.         iface->forw = NULLIF;
  51.     } else {
  52.         if(iface1->output != iface->output)
  53.             printf("Warning: Interfaces of different type\n");
  54.         iface->forw = iface1;
  55.     }
  56.     return 0;
  57. }
  58.